package com.sakura.taos.tool.manipulator.model.layui;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * lay 的返回类型对象--数据类型
 *
 * @author 小坤坤
 * @date 2020/7/10 17:02
 */
@Data
@ApiModel(value="lay的列表数据返回",description="增加了数据总数和返回具体数据内容")
public class LayReturnToData<E> extends LayReturn {
    /**
     * 数据长度
     */
    @ApiModelProperty(value="查询结果总数",example="100")
    private Long count;
    /**
     * 返回的数据
     */
    @ApiModelProperty(value="查询结果集",example="[{Key:Value,Key:Value},{Key:Value}]")
    private List<E> data;

    public LayReturnToData() {
    }

    public LayReturnToData(Integer code, String msg, List<E> data) {
        super.setCode(code);
        super.setMsg(msg);
        this.count = data.size()>0?data.size():0L;
        this.data = data;
    }

    public LayReturnToData(Page<E> page) {
        super.setCode(0);
        super.setMsg("OK");
        this.count =page.getTotal();
        this.data = page.getRecords();
    }
    public LayReturnToData(Page<E> page, List<E> list) {
        super.setCode(0);
        super.setMsg("OK");
        this.count =page.getTotal();
        this.data = list;
    }
    public LayReturnToData(Integer code, String msg,Page<E> page) {
        setCode(code);
        super.setMsg(msg);
        this.count = page.getTotal();
        this.data = page.getRecords();
    }

}
